package com.example.code.juc;

/**
 * 单例模式
 */
public class SingletonDemo1 {
    private volatile static SingletonDemo1 instance; //声明成 volatile

    private SingletonDemo1() {
    }

    public static SingletonDemo1 getSingleton() {
        if (instance == null) {
            synchronized (SingletonDemo1.class) {
                if (instance == null) {
                    instance = new SingletonDemo1();
                }
            }
        }
        return instance;
    }

}
